<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//
namespace AuctionCore\Account;
use  AuctionCore\System\AuctionException;


/**
* 用户登录日志
* @author       爱民
*/
class LoginLog {

    //登录日志
    //$log_info(用户id,平台 0 web 1 android 2 ios,登录ip,token)
    public static function save($uid,$dev_type,$uniq_token,$ip,$app_id=2){
        //id,用户，登录时间,最后活动时间,在线时长,登录平台，登录ip,uniq_login_token,应用id(1网站用户,2来拍车用户)
        $info = array();
        $info['uid'] = $uid;
        $now = date('Y-m-d H:i:s',time());
        $info['login_time'] = $now; 
        $info['las_act_time'] = $now;
        $info['dev_type'] = $dev_type;
        $info['login_ip'] = $ip;
        $info['uniq_token'] = $uniq_token;
        $info['app_id'] = $app_id;

        $id = M('login_log')->add($info);
        return $id;
    }

    //更新活动时间
    public static function up_act_time($uniq_token){
        $ris = new \AuctionCore\Common\PhpRedis();
        $ris = $ris->getRedis();
        $now = date('Y-m-d H:i:s',time());
        //$list_key = 'login_log_up_list';
        $list_key = getRedisKeyByCode('REDIS_KEY','100008');
        $ris->lpush($list_key,$uniq_token.'|=|'.$now);
        $len = $ris->llen($list_key);
        if($len>=100){
            $log = M('login_log');
            for ($i=0; $i <$len; $i++) { 
                $val = $ris->rpop($list_key);
                $row = explode('|=|', $val);
                $uniq_token = $row[0];
                $now = $row[1];
                
                $data = array('las_act_time'=>$now);
                $ok = $log->where("uniq_token='{$uniq_token}'")->save($data);    
            }
        }          
    }

}



?>